package com.hq.ims.data.service;

import com.hq.ims.data.dao.LogUserLoginInfoMapper;
import com.hq.ims.data.entity.LogUserLoginInfo;
import com.hq.ims.data.vo.LogUserLoginInfoMapstruct;
import com.hq.mybatis.base.BaseService;
import com.hq.mybatis.base.page.RequestPage;
import com.hq.utils.util.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * jiang bai ping
 *
 * @Email 526666031@qq.com
 * @Detail 用户登录日志服务实现类
 */
@Service
public class BaseLogUserLoginInfoService extends BaseService<LogUserLoginInfoMapper, LogUserLoginInfo> {

    public List<LogUserLoginInfo> getByPage(
            RequestPage page,
            LogUserLoginInfoMapstruct.PageSearchVo searchData
    ) {
        //根据传递的搜索参数进行检索
        this.lambdaQuery()
                .like(StringUtils.isNotEmpty(searchData.getUserAccount()), LogUserLoginInfo::getUserAccount, searchData.getUserAccount())
                .ge(searchData.getBeginTime() != null, LogUserLoginInfo::getCreateDateTime, searchData.getBeginTime())
                .le(searchData.getEndTime() != null, LogUserLoginInfo::getCreateDateTime, searchData.getEndTime())
                .eq(LogUserLoginInfo::getIsDel, false)
                .orderByDesc(LogUserLoginInfo::getCreateDateTime)
                .page(page);

        List<LogUserLoginInfo> records = page.getRecords();
        return records;
    }

    /**
     * 清除日志成功
     */
    public Boolean clearLogByTime(LogUserLoginInfoMapstruct.ClearLogVo clearLogVo) {
        //通过日志id+时间区间清除日志
        return this.lambdaUpdate()
                .ge(clearLogVo.getBeginTime() != null, LogUserLoginInfo::getCreateDateTime, clearLogVo.getBeginTime())
                .le(clearLogVo.getEndTime() != null, LogUserLoginInfo::getCreateDateTime, clearLogVo.getEndTime())
                .remove();
    }
}
